package com.aaa.service.sds.impl;

import com.aaa.dao.sds.PlanSdsDao;
import com.aaa.dao.view.ViewsDao;
import com.aaa.entity.system.PageEnty;
import com.aaa.entity.sds.PlanSds;
import com.aaa.service.sds.PlanSdsService;
import com.aaa.utils.MyRandom;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 测试计划sds(PlanSds)表服务实现类
 *
 * @author makejava
 * @since 2022-09-01 19:18:03
 */
@Service("planSdsService")
public class PlanSdsServiceImpl implements PlanSdsService {
    @Autowired
    private PlanSdsDao planSdsDao;
    @Autowired
    ViewsDao viewsDao;

    /**
     * @create by: Teacher马
     * @description:  分页排序 功能
     * @create time:

     * @return
     */
    @Override
    public Page queryAllPlanSdsPage(PageEnty pageEnty, PlanSds planSds) {
        PageHelper.startPage(pageEnty.getPage(), pageEnty.getLimit(), pageEnty.getOrder());
        List<Map<String, Object>> mapList = planSdsDao.queryAllPlanSdsPage(planSds);
        Page page= (Page) mapList;
        return page;
    }

    /**
     * @create by: Teacher马
     * @description:  添加随机数 调用视图里边的方法
     * @create time:

     * @return
     */
    @Override
    public boolean savePlanSds(PlanSds planSds) {
        List<Integer> integers = viewsDao.queryView();
        int myRan = MyRandom.myRan(integers);
        planSds.setTestCode(myRan);
        boolean savePlanSds = planSdsDao.savePlanSds(planSds);
        return  savePlanSds;
    }

    /**
     * @create by: Teacher马
     * @description:  删除
     * @create time:

     * @return
     */
    @Override
    public boolean deletePlanSds(int[] id) {
        return planSdsDao.deletePlanSds(id);
    }

    /**
     * @create by: Teacher马
     * @description:  修改
     * @create time:

     * @return
     */
    @Override
    public boolean updatePlanSds(PlanSds planSds) {
        return planSdsDao.updatePlanSds(planSds);
    }

    /**
     * @create by: Teacher马
     * @description:  检查重复名
     * @create time:

     * @return
     */
    @Override
    public boolean repetitionName(PlanSds planSds) {
        Integer integer = planSdsDao.repetitionName(planSds);
        if (integer>0){
            return false;
        }
        return true;
    }
    /**
     * @create by: Teacher马
     * @description:  查询下拉框
     * @create time:

     * @return
     */
    @Override
    public List<PlanSds> queryAll() {
        return planSdsDao.queryAll();
    }
}
